ValueFolderTemp='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsJournal\';
ValueFolderTemp2='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsEditor\';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\Results\NCoAuthorsEditors.mat');
VecResultsCoAuthorsTemp=VecResultsCoAuthors;
VecValueJournalStart=xlsread('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\pubmed\DonneesNature.xlsx',1);
ValueCutoff=1.25;
VecFigure=[];
VecFigure2=[];
VecFigure3=[];
VecFigure5=[];
VecResultsCoAuthors=[];
VecResultsCoAuthors2=[];
VecResultsCoAuthors3=[];
VecResultsEditorsCoAuthorsTemp=zeros(1,4);
VecResultsEditorAfter=[];
VecResultsEditorBefore=[];
VecResultsEditorTemp2=[];
VecResultsEditorCoAuthors=[];
VecResultsEditorCoAuthors2=[];
VecResultsEditorJournal=[];
VecResultsEditorJournal2=[];
VecResultsTemp5Temp=[];
VecA=192:1:198;
VecA=[VecA 65];
Veca=224:1:230;
Veca=[Veca 97];
VecC=[199 67];
Vecc=[231 99];
VecE=200:203;
VecE=[VecE 69];
Vece=232:1:235;
Vece=[Vece 101];
VecI=204:207;
VecI=[VecI 73];
Veci=236:1:239;
Veci=[Veci 105];
Vecn=[241 110];
VecO=210:214;
VecO=[VecO 216 79];
Veco=242:1:246;
Veco=[Veco 248 111];
VecU=217:1:220;
VecU=[VecU 85];
Vecu=249:1:252;
Vecu=[Vecu 117];
VecY=[221 89];
Vecy=[253 121];
Vecs=[223 115];
VecSpecialCharacters=[{VecA} {Veca} {VecC} {Vecc} {VecE} {Vece} {VecI} {Veci} {Vecn} {VecO} {Veco} {VecU} {Vecu} {VecY} {Vecy} {Vecs}];
for n1=1:323
    n1
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    n5Temp5=0;
    if size(ValueTemp,1)==1&&n1~=11
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            load([ValueFolderTemp2 'ResultsCharacteristicsEditor' num2str(n1) '.mat']);
            ValueJournal=VecValueEditor{n1,11};
            n3=1;
            TestTemp=0;
            while n3<=size(VecValueJournal,1)&&TestTemp==0
                if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                    TestTemp=1;
                else
                    n3=n3+1;
                end
            end
%             ValueFileTemp4=dir([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
%             if size(ValueFileTemp4,1)==1
                load([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
                load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
                VecValueTemp24=[];
                VecValueTemp25=[];
                VecValueTemp24Temp=[];
                VecValueTemp25Temp=[];
                ValueTime=clock();
                n5Temp=0;
                for n2=1:33
                    if n2==n3
                        eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
                        VecResultsTemp5Temp=[VecResultsTemp5Temp;size(VecValueTemp22,1) size(VecValueTemp2,2) VecResultsCoAuthorsTemp(n1,1:3)];
                    else
%                         if VecResultsEditor(1,16)<VecValueJournalStart(n2,5)||VecResultsEditor(1,16)>VecValueJournalStart(n2,6) % Exclusion of journals which have been launched during the two years after the editor's appointment (to be commented to get all journals)
%                             eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1;']);
%                             if size(VecValueTemp,2)>=1 % To keep only co-authors who published before the editor's appointmenet in the anlaysis of article spublished by co-authors only in the editor's journal and the other journals
%                                 ValueTemp4=find(VecValueTemp(2,:)>0);
%                                 VecValueTemp=VecValueTemp(:,ValueTemp4);
%                                 eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                                 VecValueTemp2=VecValueTemp2(:,ValueTemp4);
%                             end
                            eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1Filtered;']); % robustness analysis for the first group of co-authors
                            if size(VecValueTemp24,2)==0&&size(VecValueTemp,2)>=1
                                VecValueTemp24=VecValueTemp;
                                VecValueTemp25=VecValueTemp;
%                                 eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
                                eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                                VecValueTemp24Temp=VecValueTemp2;
                                n5Temp=n5Temp+1;
                            else
                                if size(VecValueTemp,2)>=1
%                                     eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
                                    eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                                    for n4=1:size(VecValueTemp2,2)
                                        n5=1;
                                        TestTemp=0;
                                        while TestTemp==0&&n5<=size(VecValueTemp24Temp,2)
                                            if size(VecValueTemp24Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp24Temp{1,n5}-VecValueTemp2{1,n4}))==0
                                                TestTemp=1;
                                            else
                                                n5=n5+1;
                                            end
                                        end
                                        if n5<=size(VecValueTemp24Temp,2)
                                            VecValueTemp24(:,n5)=VecValueTemp24(:,n5)+VecValueTemp(:,n4);
                                        else
                                            VecValueTemp24(:,n5)=VecValueTemp(:,n4);
                                            VecValueTemp24Temp(1,n5)={VecValueTemp2{1,n4}};
                                        end
                                        n5Temp=n5Temp+1;
                                    end
                                    VecValueTemp25=[VecValueTemp25 VecValueTemp];
                                    if size(VecValueTemp2,2)>0
                                        n5Temp5=n5Temp5+1;
                                    end
                                end
                            end
%                         end
                    end
%                     eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m1;']);
%                     if size(VecValueTemp25,2)==0&&size(VecValueTemp,2)>=1
%                         VecValueTemp25=VecValueTemp;
%                         eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                         VecValueTemp25Temp=VecValueTemp2;
%                     else
%                         if size(VecValueTemp,2)>=1
%                             eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                             for n4=1:size(VecValueTemp2,2)
%                                 n5=1;
%                                 TestTemp=0;
%                                 while TestTemp==0&&n5<=size(VecValueTemp25Temp,2)
%                                     if size(VecValueTemp25Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp25Temp{1,n5}-VecValueTemp2{1,n4}))==0
%                                         TestTemp=1;
%                                     else
%                                         n5=n5+1;
%                                     end
%                                 end
%                                 if n5<=size(VecValueTemp25Temp,2)
%                                     VecValueTemp25(:,n5)=VecValueTemp25(:,n5)+VecValueTemp(:,n4);
%                                 else
%                                     VecValueTemp25(:,n5)=VecValueTemp(:,n4);
%                                     VecValueTemp25Temp(1,n5)={VecValueTemp2{1,n4}};
%                                 end
%                             end
%                         end
%                     end
                end
                ValueTime2=clock();
                ValueTimeTemp=(ValueTime2(1,4)-ValueTime(1,4))*60+ValueTime2(1,5)-ValueTime(1,5);
                VecValueTemp24=VecValueTemp24';
                VecValueTemp24Temp=VecValueTemp24;
                if size(VecValueTemp22,1)>=1
                    ValueTemp5=find(isnan(VecValueTemp22(:,2))==0);
                    ValueTemp5=size(ValueTemp5,1);
                else
                    ValueTemp5=0;
                end
                if size(VecValueTemp24,1)>=1
                    ValueTemp4=find(isnan(VecValueTemp24(:,2))==0);
                    VecResultsCoAuthors=[VecResultsCoAuthors;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16) VecResultsCoAuthorsTemp(n1,1:3)];
                else
                    VecResultsCoAuthors=[VecResultsCoAuthors;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16) VecResultsCoAuthorsTemp(n1,1:3)];
                end
                VecValueTemp24=VecValueTemp25';
                if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3
%                 if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,1)<=15&&VecResultsCoAuthors(end,1)>=1
%                 if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,5)<=13
                    % First column of VecValueTemp22 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                    VecFigure3=[VecFigure3;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
                    VecFigure3=[VecFigure3;VecValueTemp23 VecValueTemp23(:,1)+VecValueTemp23(:,2) VecValueTemp23(:,1)-VecValueTemp23(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp23,1),1) n3*ones(size(VecValueTemp23,1),1) 2*ones(size(VecValueTemp23,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp23,1),1) n1*ones(size(VecValueTemp23,1),1)];
                    ValueTemp=find(VecValueTemp22(:,1)==0&VecValueTemp22(:,2)>0);
                    ValueTemp2=find(VecValueTemp23(:,1)==0&VecValueTemp23(:,2)>0);
                    VecFigure5=[VecFigure5;size(ValueTemp,1) size(VecValueTemp22,1) size(ValueTemp2,1) size(VecValueTemp23,1)];
                    VecResultsEditorCoAuthors=[VecResultsEditorCoAuthors;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    if sum(VecValueTemp22(:,2))==0
                        if sum(VecValueTemp22(:,1))>0
                            VecResultsEditorsCoAuthorsTemp(1,1)=VecResultsEditorsCoAuthorsTemp(1,1)+1;
                        else
                            VecResultsEditorsCoAuthorsTemp(1,2)=VecResultsEditorsCoAuthorsTemp(1,2)+1;
                        end
                    else
                        if sum(VecValueTemp22(:,1))>0
                            VecResultsEditorsCoAuthorsTemp(1,3)=VecResultsEditorsCoAuthorsTemp(1,3)+1;
                        else
                            VecResultsEditorsCoAuthorsTemp(1,4)=VecResultsEditorsCoAuthorsTemp(1,4)+1;
                        end
                    end
                    if size(VecValueTemp24Temp,1)>=1
                        ValueTemp4=find(isnan(VecValueTemp24Temp(:,2))==0);
                        VecResultsCoAuthors3=[VecResultsCoAuthors3;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                    else
                        VecResultsCoAuthors3=[VecResultsCoAuthors3;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                    end
                else
                    if size(VecValueEditor{n1,22},2)<=3
                        VecResultsEditorCoAuthors2=[VecResultsEditorCoAuthors2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    end
                end
                if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,1)<=15&&VecResultsCoAuthors(end,1)>=1
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,4)<=50
                    % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                    VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2)) (VecValueTemp24(:,1)-VecValueTemp24(:,2)) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                    VecFigure2=[VecFigure2;VecValueTemp24 VecValueTemp24(:,1)+VecValueTemp24(:,2) VecValueTemp24(:,1)-VecValueTemp24(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                    VecResultsEditorJournal=[VecResultsEditorJournal;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    if size(VecValueTemp24Temp,1)>=1
                        ValueTemp4=find(isnan(VecValueTemp24Temp(:,2))==0);
                        VecResultsCoAuthors2=[VecResultsCoAuthors2;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                    else
                        VecResultsCoAuthors2=[VecResultsCoAuthors2;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                    end
                else
                    if size(VecValueEditor{n1,22},2)<=3
                        VecResultsEditorJournal2=[VecResultsEditorJournal2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    end
                end
%                 % Robustness analysis (we average over the number of Nature journals)
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&n5Temp5>0
%                     % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
%                     VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
% %                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp5 VecValueTemp24(:,1)+VecValueTemp24(:,2) (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp5 VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                 end
%             end
        end
    end
end
